import random

def generate_random_integers(_sum, n):  
    mean = _sum / n
    variance = int(0.25 * mean)

    min_v = mean - variance
    max_v = mean + variance
    array = [min_v] * n

    diff = _sum - min_v * n
    while diff > 0:
        a = random.randint(0, n - 1)
        if array[a] >= max_v:
            continue
        array[a] += 1
        diff -= 1
    print(array)

# sum of 30
# 5 of them
generate_random_integers(30, 5)
